﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Profile;
using System.ComponentModel.DataAnnotations;
using VietPublisher.BaseProject.Models.cart;
using VietPublisher.BaseProject.Utils.Miscellaneous;





namespace VietPublisher.BaseProject.Models
{
    public class Profile : ProfileBase
    {

        [SettingsAllowAnonymous(false)]
        public Cart cart
        {
            get
            {
                return ((Cart)(this.GetPropertyValue(DConst.propertyName)));
            }
            set
            {
                this.SetPropertyValue(DConst.propertyName, (Cart)(value));
            }
        }

        public static Profile GetProfile(string userName)
        {
            return Create(userName) as Profile;
        }

        public static void SaveProfile(Cart cart )
        {
            string userName = string.Empty;

            //check session is null ?
            if (HttpContext.Current.Session[DConst.userName] != null) {
                userName = HttpContext.Current.Session[DConst.userName].ToString();
            }          

            if (userName != string.Empty)
            {
                Profile profile = GetProfile(userName);
                profile.cart = cart;
                //save Profile to database
                profile.Save();
            }
        }

    }
}